package com.binance.rabbitmq.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
 * Created by robin.wu on 2018/12/6.
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@Log4j2
@ConfigurationProperties
public class AlternateConfig extends AbstractConfig {

    @NestedConfigurationProperty
    private ExchangeConfig alternateExchange;
    @NestedConfigurationProperty
    private QueueConfig alternateQueue;

    private String routingKey;


    @Override
    public boolean validate() {
        log.info("Validating AlternateConfig...");

        boolean valid = true;
        if(alternateExchange != null && alternateExchange.validate()) {
            log.info("AlternateConfig configuration validated successfully for alternateExchange '{}'", alternateExchange);
        }else {
            valid = false;
        }

        if(alternateQueue != null && alternateQueue.validate()) {
            log.info("AlternateConfig configuration validated successfully for alternateQueue '{}'", alternateQueue);
        }else {
            valid = false;
        }

        return valid;
    }
}
